package com.df.tv.launcher.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.df.tv.launcher.R;
import com.df.tv.launcher.params.ComParams;

/**
 * Dialog generator
 * 
 * @author liubaolin
 * 
 */
public class DialogGenerator {
    private Context mContext;
    private Dialog mDialog;

    public DialogGenerator(Context context) {
        mContext = context;
    }

    public boolean isShowing() {
        return (mDialog != null) && mDialog.isShowing();
    }

    public void dismiss() {
        if (isShowing()) {
            mDialog.dismiss();
        }
    }

    public void createUsbDetectedDialog() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.popwindow_usb, null);
        mDialog = new Dialog(mContext, R.style.dialog);
        mDialog.setContentView(view);
        Button open = (Button) view.findViewById(R.id.btn_open_usb);
        Button cancel = (Button) view.findViewById(R.id.btn_cancel_usb);
        open.setOnClickListener(new MyOnClickListener());
        cancel.setOnClickListener(new MyOnClickListener());
        mDialog.show();
    }

    private class MyOnClickListener implements OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.btn_open_usb:
                mContext.startActivity(new Intent(ComParams.USB_OPERATION_ACTION));
                break;
            case R.id.btn_cancel_usb:
                dismiss();
            default:
                break;
            }
        }

    }

}
